package tr.com.netgis.pojo;

import java.text.MessageFormat;

/**
 * 
 * @author NetGis
 * 
 */
public class Message {

	public static class Command {
		private tr.com.netgis.util.Command command = tr.com.netgis.util.Command.UNKNOWN;
		private String value = "";

		public tr.com.netgis.util.Command getCommand() {
			return command;
		}

		public void setCommand(tr.com.netgis.util.Command command) {
			this.command = command;
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}

		private Command(tr.com.netgis.util.Command command, String value) {
			super();
			this.command = command;
			this.value = value;
		}

		private Command() {
			super();
		}

	}

	private int _id;
	private String sender;
	private String time;
	private String type;
	private String messageHeader;
	private String messageBody;
	private String command;
	private String commandParameter;
	private boolean _cb; // used for in listing

	public Message() {
		this._cb = false;
	}

	public boolean is_cb() {
		return _cb;
	}

	public void set_cb(boolean _cb) {
		this._cb = _cb;
	}

	public int get_id() {
		return _id;
	}

	public void set_id(int _id) {
		this._id = _id;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getMessageHeader() {
		return messageHeader;
	}

	public void setMessageHeader(String messageHeader) {
		this.messageHeader = messageHeader;
	}

	public String getMessageBody() {
		return messageBody;
	}

	public void setMessageBody(String messageBody) {
		this.messageBody = messageBody;
	}

	public String getCommand() {
		return command;
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public String getCommandParameter() {
		return commandParameter;
	}

	public void setCommandParameter(String commandParameter) {
		this.commandParameter = commandParameter;
	}
	
	public Command getOutCommand (){
		if (this.command == null || "".equals(this.command) )
			return new Command(tr.com.netgis.util.Command.UNKNOWN, null);
		Command command = new Command();
		int code = -99;
		try {
			code = Integer.parseInt(this.command);
		} catch (Exception e) {
		}
		command.setCommand(tr.com.netgis.util.Command.valueOf(code));
		command.setValue(this.commandParameter);
		return command;
	}

	public String toString() {
		return MessageFormat
				.format("[sender:{0}, time: {1}, type: {2}, message-header: {3},"
						+ "message-body: {4}, command: {5}, command-parameter: {6}]",
						sender, time, type, messageHeader, messageBody,
						command, commandParameter);
	}
}